﻿@model Mix.Cms.Lib.ViewModels.MixPosts.ReadMvcViewModel
@{
    string master = MixService.GetConfig<string>(MixAppSettingKeywords.ThemeName, ViewBag.culture);
    string templateFolder = MixCmsHelper.GetTemplateFolder(ViewBag.culture);
    string layout = "Masters/_Layout.cshtml";
    var masterTemplate = await MixCmsHelper.GetTemplateByPath(master, layout);
    Layout = $"{templateFolder}/{layout}";
}
@if (Model != null)
{
    <div>
        <preview-popup ng-if="isInit" preview-object="previewObject"></preview-popup>

        <input type="hidden" id="view-type" value="Post" />
        <input type="hidden" id="view-id" value="@Model.Id" />
        @if (!string.IsNullOrEmpty(Model.TemplatePath))
        {
            try
            {
                <partial name="@Model.TemplatePath" model="@Model" />
            }
            catch (System.InvalidOperationException invalidOperationException)
            {
                <p class="danger text-center has-error">Unable load template with Exception detail below:</p>
                <code>
                    @invalidOperationException
                </code>

            }
            catch (Exception ex)
            {
                <code>
                    @ex
                </code>
                <p class="danger text-center has-error">Unable load template</p>
            }
        }
        else
        {
            <section class="container">
                <h1>@(MixService.Translate<string>("Please choose template", ViewBag.culture))</h1>
            </section>
        }
    </div>
}
else
{
    <h1>NotFound</h1>
}
@{
    string url = ViewData["OgUrl"] != null ? (string)ViewData["OgUrl"] : Model.DetailsUrl;
    string title = ViewData["OgTitle"] != null ? (string)ViewData["OgTitle"] : Model.SeoTitle;
    ViewData["Title"] = ViewData["Title"] != null ? (string)ViewData["Title"] : Model.SeoTitle;
    string desc = ViewData["OgDescription"] != null ? (string)ViewData["OgDescription"] : Model.SeoDescription;
    string image = ViewData["OgImage"] != null ? (string)ViewData["OgImage"] : Model.ThumbnailUrl;

    var domain = url.IndexOf("http") == -1 ? $"{Context.Request.Scheme}://{Context.Request.Host}" : string.Empty;
}
@section Seo{
    <title>@(MixService.GetConfig<string>("SiteName", ViewBag.culture)) - @Model.SeoTitle</title>
    <meta property="og:type" content="website" />
    <!--points to the regular HTML version of the AMP HTML document or to itself if no such HTML version exists-->
    <link rel="canonical" href="@domain@url">
    <meta property="og:url" content="@domain@url" />
    <meta property="og:title" content="@title" />
    <meta property="og:description"
          content="@desc" />
    <meta property="og:image" content="@image" />
    <meta name="title" content="@title" />
    <meta name="description" content="@desc" />
    <meta name="keywords" content="@desc" />
}

@section Styles{
    @Html.Raw(masterTemplate?.Styles)
    @Html.Raw(Model.View?.Styles)
}
@section Scripts{
    @Html.Raw(masterTemplate?.Scripts)
    @Html.Raw(Model.View?.Scripts)
}
